import java.awt.*;
import java.util.*;
import java.util.List;
import java.util.logging.Level;
import javax.accessibility.*;
import javax.swing.*;

import org.rsbot.bot.Bot;
import org.rsbot.script.*;
import org.rsbot.script.wrappers.*;
import org.rsbot.accessors.*;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.event.listeners.ServerMessageListener;
import org.rsbot.event.events.ServerMessageEvent;
import org.rsbot.util.ScreenshotUtil;

@ScriptManifest(authors = { "Frewbie" }, category = "Fishing", name = "LobsterFisher", version = 0.04, description = "<html><head></head><body><h2>LobsterFisher</h2><br />Start the script at a lobster spot.</body></html\n")
public class LobsterFisher extends Script implements PaintListener, ServerMessageListener {
	
	public int fishingAnim = 1;
	public int lobsterCage = 1;
	public int lobster;
	public int exp = lobster * 350;
	public RSObject fishingSpot = 1;
	public String status;

    private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);

    public boolean onStart(Map<String, String> args) {
    	status = "Starting script";
    	if(40 > STAT_FISHING) {
    		log("You can't even catch lobsters..");
    		return false;
    	}
        return true;
    }

    public int loop() {
    	if(getMyPlayer().isMoving()) {
    		status = "Walking to lobster spot";
    		return(random(253, 1483));
    	}
    	
    	if(isInventoryFull()) {
    		status = "Your inventory is full";
    		dropAllExcept(lobsterCage);
    		return(random(342, 946));
    	}
    	
		if(getMyPlayer().getAnimation() == fishingAnim) {
			status = "Fishing";
			return(random(276,2573));
		}
		
		if(!getNearestObjectByID(fishingSpot)) {
			log("Please stand nearby a lobster spot");
			return -1;
		}
		
		if(!inventoryContains(lobsterCage)) {
			log("You need a lobster cage");
			return -1;
		}
		
		atObject(fishingSpot, "Cage");
				return random(356, 792);
    }
    
    public void serverMessageRecieved(final ServerMessageEvent arg0) {
        final String serverString = arg0.getMessage();
        
        if(serverString.contains("You caught a lobster")) {
        	lobster++;
        }
    }
        
    public void onRepaint(Graphics g) {
        if(!isLoggedIn() ||  isLoginScreen()) {
            return;
        }
        g.draw3DRect(0, 0, 300, 100, true);
        g.drawString("Status" + status, 5, 5);
        g.drawString("Lobsters caught: " + lobster, 5, 10);
        g.drawString("Experience gained: " + exp, 5, 10);
    }
    
    public void onFinish() {
        ScreenshotUtil.takeScreenshot(true);
        log("Thanks for using Frewbie's power LobsterFisher")
    }
}